#!/bin/bash
# Author: PortWINE-Linux.ru
. "$(dirname $(readlink -f "$0"))/runlib"

rm -f "${PORT_WINE_PATH}/"*".log" 
rm -f "${config_path}/update_notifier"

if [ ! -d "/home/${USER}/.local/share/applications" ]
then
	mkdir -p "/home/${USER}/.local/share/applications"
fi

name_desktop="${gamename}" 
echo "[Desktop Entry]"	 				  > "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "Name=${name_desktop}" 				 >> "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "Exec="${PORT_WINE_PATH}/data/scripts/start""	 >> "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "Type=Application" 				 >> "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "Categories=Game"	    				 >> "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "StartupNotify=true" 	    			 >> "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "Path="${PORT_WINE_PATH}/data/scripts/""		 >> "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "Icon="${PORT_WINE_PATH}/data/img/w.png""   	 >> "${PORT_WINE_PATH}/${name_desktop}.desktop"
chmod u+x "${PORT_WINE_PATH}/${name_desktop}.desktop"
cp -f "${PORT_WINE_PATH}/${name_desktop}.desktop" /home/${USER}/.local/share/applications/ 

name_desktop="readme" 
echo "[Desktop Entry]"					 > "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "Name=${name_desktop}"				>> "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "Version=1.0"					>> "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "Type=Link"					>> "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "Icon="${PORT_WINE_PATH}/data/img/readme.png""	>> "${PORT_WINE_PATH}/${name_desktop}.desktop"
echo "URL=${urlg}" >> "${PORT_WINE_PATH}/${name_desktop}.desktop"
chmod u+x "${PORT_WINE_PATH}/${name_desktop}.desktop"

rm -fR "${PORT_WINE_PATH}/Settings"
mkdir -p "${PORT_WINE_PATH}/Settings"

for name_desktop in "winecfg" "winefile" "wineboot" "winecmd" "winereg"
do
echo ""[Desktop Entry]"
"Name=${name_desktop}"
"Exec="${PORT_WINE_PATH}/data/scripts/${name_desktop}""
"Type=Application"
"Categories=Game"
"StartupNotify=true"
"Path="${PORT_WINE_PATH}/data/scripts/""
"Icon="${PORT_WINE_PATH}/data/img/s.png""" > "${PORT_WINE_PATH}/Settings/${name_desktop}.desktop"
chmod u+x "${PORT_WINE_PATH}/Settings/${name_desktop}.desktop"
done

for name_desktop in "remove" "debug" "restart"
do
echo ""[Desktop Entry]"
"Name=${name_desktop}"
"Exec="${PORT_WINE_PATH}/data/scripts/${name_desktop}""
"Type=Application"
"Categories=Game"
"StartupNotify=true"
"Path="${PORT_WINE_PATH}/data/scripts/""
"Icon="${PORT_WINE_PATH}/data/img/s.png""" > "${PORT_WINE_PATH}/${name_desktop}.desktop"
chmod u+x "${PORT_WINE_PATH}/${name_desktop}.desktop"
done

echo ""[Desktop Entry]"
"Name=winetricks"
"Exec="${PORT_WINE_PATH}/data/scripts/winetricks-q-force""
"Type=Application"
"Categories=Game"
"StartupNotify=true"
"Path="${PORT_WINE_PATH}/data/scripts/""
"Icon="${PORT_WINE_PATH}/data/img/s.png""" > "${PORT_WINE_PATH}/Settings/winetricks.desktop"
chmod u+x "${PORT_WINE_PATH}/Settings/winetricks.desktop"

chmod u+x "${PORT_WINE_PATH}/data/scripts/"*
ln -s "${PORT_WINE_PATH}/data/pfx/drive_c/" "${PORT_WINE_PATH}/drive_c"

sed -i "s/xuser/${USER}/g" "${PORT_WINE_PATH}/data/pfx/"*.reg

ADD_IN_POST_INSTALL

xdg-open "http://portwine-linux.ru/portwine-faq/" > /dev/null 2>&1  & exit 0  
